package website.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class AddServlet extends HttpServlet {

	private RequestDispatcher addJsp;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		ServletContext context = config.getServletContext();
		addJsp = context.getRequestDispatcher("/WEB-INF/jsp/add.jsp");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
				
		double a = Double.parseDouble(req.getParameter("1"));
		double b = Double.parseDouble(req.getParameter("2"));
		Double sum = new Double(a+b);
		
		req.setAttribute("sum", sum.toString());
		addJsp.forward(req, resp);
	}
}
